﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Intelligent.OTC.WebApi.Core;
using Intelligent.OTC.Domain.DataModel;
using Intelligent.OTC.Business;
using Intelligent.OTC.Common;
using Intelligent.OTC.Common.Attr;

namespace Intelligent.OTC.WebApi.Controllers
{
    [UserAuthorizeFilter(actionSet: "dispute")]
    public class DisputeTrackingController : ApiController
    {
        [HttpGet]
        [PagingQueryable]
        public IEnumerable<DisputeTrackingView> Get()
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            return service.GetDisputeDatas().AsQueryable();
        }

        [HttpGet]
        public List<string> GetDisputeById(int id) 
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            return service.GetDisputeById(id);
        }

        [HttpGet]
        public IEnumerable<DisputeTracking> GetDisputeInvoiceDatas(int disId) 
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            return service.GetDisputeInvoiceDatas(disId).AsQueryable();
        }

        [HttpGet]
        public IEnumerable<DisputeHis> GetDisputeStatusChange(int disputeid)
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            return service.GetDisputeStatusChange(disputeid).AsQueryable();
        }

        //save Notes
        [HttpPost]
        public void SaveNotes([FromBody]List<string> list)
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            service.SaveNotes(int.Parse(list[0]), list[1]);
        }

        [HttpPost]
        [Route("api/disputeTracking/sendMail")]
        public void SendDisputeMail([FromBody]MailTmp mail)
        {
            DisputeTrackingService service = SpringFactory.GetObjectImpl<DisputeTrackingService>("DisputeTrackingService");
            service.SendDisputeMail(mail);
        }
    }
}